﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using secondhand.L3object;
using System.Data;
using secondhand.L1database;

namespace secondhand.L2busslogic
{
    public class salerBL
    {
        public static salerOB Getmark()     //获取数据库中的大单条数据
        {
            string commandtext = "select * from saler ";
            salerOB myword = new salerOB();       //数据库对象
            myword.saler_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = salerDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.saler_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.pass_word = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.saler_num = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.saler_mail = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.saler_count = ds.Tables[0].Rows[i][5].ToString().Trim();

            return myword;
        }
        public static salerOBList GetmarkAll()       //获取数据库中的所有记录
        {
            string commandtext = "select * from saler";
            salerOBList tempList = null;
            tempList = new salerOBList();
            DataSet ds = null;
            ds = salerDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                salerOB myword = new salerOB();

                myword.saler_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.pass_word = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.saler_num = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.saler_mail = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.saler_count = ds.Tables[0].Rows[i][5].ToString().Trim();
                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static bool Addfill(salerOB myword)      //添加纪录
        {
            string ss = "INSERT INTO saler (saler_name,pass_word,saler_num,saler_mail,saler_count)VALUES('";
            ss = ss + myword.saler_name.Trim() + "','";
            ss = ss + myword.pass_word.Trim() + "','";
            ss = ss + myword.saler_num.Trim() + "','";
            ss = ss + myword.saler_mail.Trim() + "','";
            ss = ss + myword.saler_count.Trim() + "')";

            return salerDB.AddDeleteItem(ss);
        }

        public static salerOB Getwordsingle(string nameq)      //按姓名查找
        {
            string commandtext = "select * from saler where saler_name='" + nameq.Trim() + "'";
            salerOB myword = new salerOB();
            myword.saler_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = salerDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.pass_word = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.saler_num = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.saler_mail = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.saler_count = ds.Tables[0].Rows[i][5].ToString().Trim();

            return myword;
        }

        
        public static bool Savemark(salerOB myword)     //修改记录
        {
            string commandtext = "update saler set  saler_name='";
            commandtext = commandtext + myword.saler_name.Trim() + "', pass_word='";
            commandtext = commandtext + myword.pass_word.Trim() + "', saler_count='";
            commandtext = commandtext + myword.saler_count.Trim() + "', saler_num='";
            commandtext = commandtext + myword.saler_num.Trim() + "', saler_mail='";
            commandtext = commandtext + myword.saler_mail.Trim() + "' where ID=";
            commandtext = commandtext + myword.ID.Trim();
            return salerDB.AddDeleteItem(commandtext);
        }
        public static bool deleteword(string name)      //删除记录
        {

            string ss = "delete from saler where saler_name='" + name.Trim() + "'";
            return salerDB.AddDeleteItem(ss);


        }
        
    }
}